<?php
/**
 * Created by PhpStorm.
 * User: DOVEGIFT
 * Date: 2019/6/20
 * Time: 11:10
 */

header("Access-Control-Allow-Origin:*");
header("Content-Type:Application/json;charset=utf-8");
if ($_SERVER["REQUEST_METHOD"] != "POST") {
    $result = array("msg" => "对不起,不支持get请求", "status" => -1);
    print_r(json_encode($result));
    return;
}
//post请求
if (!(isset($_POST["uname"]) &&isset($_POST["upwd"]))) {
    $result = array("msg" => "参数不合法", "status" => -2);
    print_r(json_encode($result));
    return;
}
include "DBhelper.php";

$uname = $_POST["uname"];
$upwd = $_POST["upwd"];

// 1.创建数据库的链接对象
$conn=new mysqli("localhost","root","","cs1902","3306");
//2.设置链接字符集
mysqli_query($conn,"set names utf8");
//3.准备sql语句
$sql="INSERT INTO `userinfo`(`u_name`,`u_pwd`)VALUES('".$uname."','".$upwd."')";

//4.执行sql语句
$dataResult=$conn->query($sql);
//5.判断结果
if ($dataResult==1){
    $result = array("msg" => "恭喜,注册成功", "status" => 1,);
    print_r(json_encode($result));
}else{
    $result = array("msg" => "对不起,注册失败", "status" => -3);
    print_r(json_encode($result));
}
//6.关闭数据库链接
$conn->close();
